package com.hualan.zhsq.service.impl.property;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.property.Announcement;
import com.hualan.zhsq.mapper.property.AnnouncmentMapper;
import com.hualan.zhsq.service.property.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AnnouncementServiceImpl
 * @Description 公告serviceImpl
 * @Author ZheRan
 * @Date 2025年08月04日 下午8:19
 * @Version 1.0
 */
@Service("announcementService")
public class AnnouncementServiceImpl  implements AnnouncementService {

    @Autowired
    private AnnouncmentMapper announcmentMapper;

    @Override
    public int add(Announcement entity) {
        return announcmentMapper.insert(entity);
    }

    @Override
    public int edit(Announcement entity) {
        return announcmentMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return announcmentMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return announcmentMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<Announcement> find() {
        return announcmentMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Announcement entity) {
        Page<Announcement> page = new Page<>(pageNum, pageSize);
        Page<Announcement> announcementPage = announcmentMapper.selectPage(page, null);
        Map<String, Object> map = new HashMap<>();
        map.put("list",announcementPage.getRecords());
        map.put("total", announcementPage.getTotal());
        map.put("size", announcementPage.getSize());
        return map;
    }

    @Override
    public Announcement findById(Integer id) {
        return announcmentMapper.selectById(id);
    }
}
